n=int(input())
nums=list(map(int,input().split()))

result=0
for i in range(1,n-1):
    if (nums[i]-nums[i-1])*(nums[i+1]-nums[i])<0:
        result+=1
print(result)
